package suncertify.gui;

import javax.swing.JTable;

import suncertify.contractors.Contractor;

/**
 * Creates class instances that implement the {@link ContractorsViewInterface}. The type of the class used to create the
 * implementation instance depends on the type of the <code>control</code> parameter. In this version, the factory only
 * recognizes <code>control</code> parameters of type {@link JTable}.
 * 
 */
public class ContractorsViewFactory {

    /**
     * Creates a class that implements the {@link ContractorsViewInterface} interface.
     * 
     * @param control
     *            An object that represents a visual component that is able to show the data provided by the
     *            <code>contractors</code> parameter. Possible value of this parameter is a reference to a
     *            {@link JTable} object.
     * @param contractors
     *            An array of {@link Contractor} objects.
     * @return See {@link ContractorsJTableView}
     */
    public static ContractorsViewInterface createContractorsView(Object control, Contractor[] contractors) {

	assert control instanceof JTable : "control is not of type JTable!";

	if (control instanceof JTable) {

	    return new ContractorsJTableView((JTable) control, contractors);
	}

	// if (control instanceof XYZTable) {
	// return new ContractorsXYZTableView((XYZTable) control, contractors);
	// }

	throw new IllegalArgumentException("Unsupported ContractorsViewFactory control.");
    }
}
